<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>23题所有约数</title>
    <script>
        function getYueNumber(flag) {
            var num = prompt(flag ? '请输入正确的正整数' : '请输入一个正整数');
            if (!/^[0-9]*$/i.test(num)) {
                getYueNumber(true);
                return;
            }
            let numStr = '';
            let len = parseInt(num);
            for (let i = 1; i <= len; i++) {
                if (len % i === 0) {
                    numStr += i;
                    if (i < len) {
                        numStr += ',';
                    }
                }
            }
            let p = document.getElementById('sum');
            p.innerHTML = num + '的所有约数为：' + numStr;
        }
    </script>
</head>
<body>
    <p>
        输入一个数，以查看其所有约数<input type="button" value="输入" onclick="getYueNumber()">
    </p>
    <p id="sum">约数：</p>
</body>
</html>